//author:jxx
//此处是对表单的方法，组件，权限操作按钮等进行任意扩展(方法扩展可参照SellOrder.js)
let extension = {
  components: {//动态扩充组件或组件路径
    //表单header、content、footer对应位置扩充的组件
    gridHeader: '',//{ template: "<div>扩展组xx件</div>" },
    gridBody: '',
    gridFooter: '',
    //弹出框(修改、编辑、查看)header、content、footer对应位置扩充的组件
    modelHeader: '',
    modelBody: '',
    modelFooter: ''
  },
  buttons: { view: [], box: [], detail: [] },//扩展的按钮
  methods: {//事件扩展
    getFormOption (field) {
      let option;
      this.editFormOptions.forEach(x => {
        x.forEach(item => {
          if (item.field == field) {
            option = item;
          }
        })
      })
      return option;
    },
    rowClick ({ row, column, event }) { //查询界面table点击行选中当前行
      this.$refs.table.$refs.table.toggleRowSelection(row);
      return true;
    },
    modelOpenBefore (row) {
      if (this.currentAction == 'Add') {

      } else {
        if (row.realauthentication != null) {
          row.realauthent = JSON.parse(row.realauthentication).map(i => i.key).join()
        }
      }
    },
    modelOpenAfter (row) {
      let isEDIT = this.currentAction == this.const.EDIT;
      if (!isEDIT) {
        // 新建时 产品类型显示 酒店id，pms房型代码，教学等级，教学时长隐藏
        let x = this.getFormOption("merchant_Name");
        x.onInput = (val) => {
          this.editFormFileds.merchant_Code = this.base.chineseToPinYin(val)
        }
        this.editFormFields.scancodeswitch = 1
      } else {
        // 将开始日期 和 结束日期合并为起止日期
        this.editFormFields.timeContainer = [row.merchantEffectiveStartTtime, row.merchantEffectiveEndTtime]
      }
    },
    addBefore (formData) { //新建保存前formData为对象，包括明细表
      return this.veriFromTable(formData)
    },
    updateBefore (formData) { //编辑保存前formData为对象，包括明细表、删除行的Id
      return this.veriFromTable(formData)
    },
    veriFromTable (formData) {
      let vb = this.getFormOption("realauthent");
      let vh = vb.data.filter(i => {
        return formData.mainData.realauthent.includes(i.key)
      })
      formData.mainData.realauthentication = JSON.stringify(vh)
      delete formData.mainData.realauthent
      let timeContainer = formData.mainData.timeContainer.split(",");
      if (timeContainer.length > 0 && timeContainer[0] != "") {
        formData.mainData.merchantEffectiveStartTtime = timeContainer[0]
        formData.mainData.merchantEffectiveEndTtime = timeContainer[1]
        return true;
      } else {
        this.$Message.error("请选择有效起止日期！")
        return false;
      }

    },
    onInit () {
      this.boxOptions.height = 450;
      this.boxOptions.width = 850;

    }
  }
};
export default extension;